#ifndef CPP_SWITCH_H
#define CPP_SWITCH_H

#include <widget/CompoundButton.h>
#include <style/SwitchStyle.h>

class Bitmap;
class Canvas;
class SwitchStyle;

//@brief 开关按钮
//@author cvte
//@description 按钮控件,做开关使用
class Switch : public CompoundButton {
   public:
    // constructor & destructor
    Switch();
    virtual ~Switch();

    void setOnStyle(SwitchStyle& drawable);
    void setOffStyle(SwitchStyle& drawable);
    void setDisableStyle(SwitchStyle& drawable);
    void setOnBitmap(int x, int y, Bitmap& bitmap);
    void setOffBitmap(int x, int y, Bitmap& bitmap);
    void setDisableBitmap(int x, int y, Bitmap& bitmap);

    //@method setShowText
    //@param showText bool 是否显示文字
    //@description 设置on/off文字是否可显示
    void setShowText(bool shouldShowText);

   protected:
    void onAttachedToWindow();
    void onDetachedFromWindow();
    void onDraw(Canvas& canvas);
    void onClicked();

   private:
    SwitchStyle* mOnStyle = nullptr;
    SwitchStyle* mOffStyle = nullptr;
    SwitchStyle* mDisableStyle = nullptr;
    Bitmap* mBitmapOn = nullptr;
    Bitmap* mBitmapOff = nullptr;
    Bitmap* mBitmapDisable = nullptr;
    int mBitmapOnX = 0;
    int mBitmapOnY = 0;
    int mBitmapOffX = 0;
    int mBitmapOffY = 0;
    int mBitmapDisableX = 0;
    int mBitmapDisableY = 0;
    bool mShouldShowText = false;
};

#endif /* CPP_SWITCH_H */